//https://leetcode.cn/problems/missing-two-lcci/

class Solution {
public:
    vector<int> missingTwo(vector<int>& nums) {
        //将所有数字异或
        int temp = 0;
        for (auto x : nums) temp ^= x;
        for (int i = 1; i <= nums.size() + 2; i++)
            temp ^= i;

        //找到a^b的不同位 即异或结果为1的那一位
        int diff = 0;
        while (1)
        {
            if (((temp >> diff) & 1) == 1) break;
            else
                diff++;
        }

        //针对diff位分成两个部分的数字进行异或
        int a = 0, b = 0;
        for (auto x : nums)
        {
            if (((x >> diff) & 1) == 1) a ^= x;
            else b ^= x;
        }

        for (int i = 1; i <= nums.size() + 2; i++)
        {
            if (((i >> diff) & 1) == 1) a ^= i;
            else b ^= i;
        }

        return { a,b };
    }
};